<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Content extends CI_Controller {
	
	function __construct() {
    parent::__construct();	
		$this->isLogin();	
		$this->load->model('content_model');
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	public function index(){
		$data['main_view']='admin/content/read';
		$data['hasil']=$this->content_model->read();
		$this->load->view('admin/template',$data);
	}
	
	function edit($id){
		$data['main_view']='admin/content/edit';
		$data['hasil']=$this->content_model->edit($id);
		$this->load->view('admin/template',$data);
	}
	
	function proses_update(){
		$id = $this->input->post('id_content');
		$data = array(
			'judul' => $this->input->post('judul'),
			'konten' => $this->input->post('konten'),
			'keyword' => $this->input->post('keyword')
		);

		if($query=$this->content_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('content');
		}
	}
}